/*
 * @lc app=leetcode.cn id=83 lang=java
 *
 * [83] 删除排序链表中的重复元素
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    //这个和82题又不同
    public ListNode deleteDuplicates(ListNode head) {
        ListNode pre = new ListNode(101);
        ListNode cur = head;
        pre.next = cur;
        while(cur!=null){
            while(cur!=null && cur.val == pre.val){
                cur = cur.next;
            }
            pre.next = cur;
            //连接上
            if(cur == null) break;//搜到末尾了，提前结束
            pre = cur;
            cur = cur.next;
        }

        return head;
    }
}
// @lc code=end

